<template>
  <div class="app-container div-style">
    <div style="position: absolute; right: 35px;">
      <div>
        <el-button type="primary" @click="submitForm">
          <svg-icon :icon-class="'save'" class="mr5"/>
          保存病例
        </el-button>
        <el-button type="primary" @click="recordPrint">
          <template #icon>
            <i-ep-printer/>
          </template>
          病历打印
        </el-button>
        <!--                <el-button type="warning" @click="submitForm">-->
        <!--                    <svg-icon :icon-class="'informed-notice'" class="mr5"/>-->
        <!--                    知情通知书-->
        <!--                </el-button>-->
      </div>
      <div class="mt10">
        <el-button type="success" @click="medicalRecordTemplateClick">
          <svg-icon :icon-class="'informed-notice'" class="mr5"/>
          病历模板
        </el-button>
        <el-button :dark="true" color="#8389e8" @click="medicalRecordHistoryClick">
                    <span style="color: #ffffff">
                        <svg-icon :icon-class="'history'"/>
                        历史病历
                    </span>
        </el-button>
      </div>
      <div class="mt10">
        <el-button type="warning" @click="generateTemplate">
          <svg-icon :icon-class="'save'" class="mr5"/>
          生成模板
        </el-button>
        <el-button type="danger" @click="clearance">
          <i-ep-delete/>
          一键清空
        </el-button>
      </div>
    </div>
    <!--        <el-row>-->
    <el-col :span="18" style="padding-bottom: 5px">
      <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item label="就诊时间：">
              <span class="mt-2">{{ clinicInfo.visitDate }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="就诊科室：">
              <span class="mt-2">{{ clinicInfo.deptName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="民族：">
                            <span class="mt-2"> {{
                                dictStore.getMateDictInfo(dictDataMap['nation_dict'], clinicInfo.nation)
                                  ?
                                  dictStore.getMateDictInfo(dictDataMap['nation_dict'],
                                    clinicInfo.nation).dictLabel
                                  : ''
                              }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="婚姻：">
                            <span class="mt-2"> {{
                                dictStore.getMateDictInfo(dictDataMap['marriage_dict'], clinicInfo.marriage)
                                  ?
                                  dictStore.getMateDictInfo(dictDataMap['marriage_dict'],
                                    clinicInfo.marriage).dictLabel
                                  : ''
                              }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="初/复诊：">
              <span class="mt-2"> {{ clinicInfo.firstVisitIndicator === 'Y' ? '初诊' : '复诊' }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="发病日期" prop="fabingriqi">
              <el-input v-model="form.fabingriqi" placeholder="请输入发病日期"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="急诊：">
                            <span class="mt-2"> {{
                                dictStore.getMateDictInfo(dictDataMap['sys_yes_no'], clinicInfo.isEmergency)
                                  ?
                                  dictStore.getMateDictInfo(dictDataMap['sys_yes_no'],
                                    clinicInfo.isEmergency).dictLabel
                                  : ''
                              }}</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="主诉" prop="zhusu">
          <el-input v-model="form.zhusu" :rows="3" placeholder="请输入内容" type="textarea"/>
        </el-form-item>
        <el-form-item label="现病史" prop="xianbingshi">
          <el-input v-model="form.xianbingshi" :rows="5" placeholder="请输入内容" type="textarea"/>
        </el-form-item>
        <el-form-item label="既往史" prop="jiwangshi">
          <el-input v-model="form.jiwangshi" :rows="5" placeholder="请输入内容" type="textarea"/>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="流行病学史" prop="liuxingbingshi">
              <el-input v-model="form.liuxingbingshi" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="个人史" prop="gerenshi">
              <el-input v-model="form.gerenshi" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="婚育史" prop="hunyushi">
              <el-input v-model="form.hunyushi" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="家族史" prop="jiazushi">
              <el-input v-model="form.jiazushi" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="月经史" prop="yuejingshi">
              <el-input v-model="form.yuejingshi" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发病后一般情况" prop="fabinghouqingkuang">
              <el-input v-model="form.fabinghouqingkuang" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="体格检查I">
            <el-col :span="4">
              <el-form-item class="tigejiancha" label="T ：" label-width="50px" prop="tiwen">
                <el-input v-model="form.tiwen" class="tigejiancha-input" clearable placeholder="体温"
                          style="width:120px">
                  <template #append>℃</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item class="tigejiancha" label="P ：" label-width="100px" prop="maibo">
                <el-input v-model="form.maibo" class="tigejiancha-input" clearable placeholder="脉搏"
                          style="width:120px">
                  <template #append>次/分</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item class="tigejiancha" label="R ：" label-width="120px" prop="huxi">
                <el-input v-model="form.huxi" class="tigejiancha-input" clearable placeholder="呼吸"
                          style="width:120px">
                  <template #append>次/分</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item class="tigejiancha" label="BP ：" label-width="150px">
                <el-input v-model="form.systolicPressure" class="tigejiancha-input" clearable
                          placeholder="收缩压" style="width:50px"/>
                <span style="margin:0 11px 0 10px">/</span>
                <el-input v-model="form.diastolicPressure" class="tigejiancha-input" clearable
                          placeholder="舒张压" style="width:50px">
                  <template #append>mmHg</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item class="tigejiancha" label="FBG ：" label-width="90px">
                <el-input v-model="form.fbg" class="tigejiancha-input" clearable placeholder="空腹血糖"
                          style="width:120px">
                  <template #append>mmol/L</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-form-item>
        </el-row>
        <el-form-item label="体格检查II" prop="tigejiancha">
          <el-input v-model="form.tigejiancha" :rows="4" placeholder="请输入内容" type="textarea"/>
        </el-form-item>
        <el-form-item label="诊断">
          <diagnosis-table ref="diagnosisTableRef" :clinic-id="clinicId" :patient-id="patientId"/>
        </el-form-item>
        <el-row>
          <el-col :span="24">
            <el-form-item label="其他诊断" prop="otherDiagnosis">
              <el-input v-model="form.otherDiagnosis" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="过敏史" prop="allergyHistory">
              <el-input v-model="form.allergyHistory" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="药物过敏史" prop="drugAllergyHistory">
              <el-input v-model="form.drugAllergyHistory" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="辅助检查" prop="fuzhujiancha">
          <el-input v-model="form.fuzhujiancha" placeholder="请输入内容" type="textarea"/>
        </el-form-item>
        <el-form-item label="小结分析" prop="xiaojiefenxi">
          <el-input v-model="form.xiaojiefenxi" placeholder="请输入内容" type="textarea"/>
        </el-form-item>
        <!-- <el-form-item label="病史采集日期" prop="bingshicaijiriqi">
            <el-date-picker clearable v-model="form.bingshicaijiriqi" type="datetime"
                value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择病史采集日期">
            </el-date-picker>
        </el-form-item> -->
        <el-form-item label="处理" prop="dispose">
          <el-input v-model="form.dispose" :rows="5" placeholder="请输入内容" type="textarea">
          </el-input>
        </el-form-item>
        <el-form-item label="建议" prop="suggestion">
          <el-input v-model="form.suggestion" placeholder="请输入内容" type="textarea"/>
        </el-form-item>
        <!-- <el-form-item label="备注信息" prop="remarks">
            <el-input v-model="form.remarks" placeholder="请输入备注信息" />
        </el-form-item> -->
      </el-form>
    </el-col>
    <!--        </el-row>-->
    <!--        <pdf-preview ref="printPreviewRef" :title="'门诊病历'"/>-->

    <!-- 历史、常用项目、模板弹出框 -->
    <el-dialog v-model="historyOpen" :close-on-click-modal="false" :title="historyTitle" append-to-body width="90%"
               @close="historyCancel">
      <div v-if="historyType === 1"></div>
      <template-quote v-else-if="historyType === 3" ref="templateQuoteRef" :query-params="templateParams"
                      @quote-ok-index="quoteOkIndex"/>
      <history v-else-if="historyType === 4" ref="historyQuoteRef" :patient-id="patientId"
               :query-params="templateParams" @history-quote="historyQuote"/>
    </el-dialog>

    <!-- 生成模板对话框 -->
    <el-dialog v-model="open" :close-on-click-modal="false" append-to-body draggable title="生成模板"
               width="500px">
      <el-form ref="formTemplateRef" :model="templateForm" :rules="rulesTemplate" label-width="100px">
        <el-form-item label="权限" prop="authorityType">
          <el-select v-model="templateForm.authorityType">
            <el-option v-for="dict in dictDataMap[
                                'template_authority_type'
                            ]" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模板名称" prop="title">
          <el-input v-model="templateForm.title" placeholder="请输入模板名称" @input="titleInput"/>
        </el-form-item>
        <el-form-item label="适用科室" prop="deptId">
          <base-dept-tree :org-id="templateForm.orgId" :value="templateForm.deptId" style="width: 100%;"
                          @deptSelect="deptSelect"/>
        </el-form-item>
        <el-form-item label="启用状态">
          <el-radio-group v-model="templateForm.startFlag">
            <el-radio v-for="dict in dictDataMap['sys_yes_no']" :key="dict.dictValue"
                      :value="dict.dictValue">{{ dict.dictLabel }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
                    <span class="dialog-footer">
                        <el-button type="primary" @click="submitFormTemplate">确 定</el-button>
                        <el-button @click="cancelTemplate">取 消</el-button>
                    </span>
      </template>
    </el-dialog>
  </div>
</template>
<script lang="ts">
export default {
  name: "ClinicRecord"
}
</script>

<script setup lang="ts">
import {
  addClinicRecord,
  listClinicRecord,
  updateClinicRecord,
  clearanceMedicalRecord
} from "@/api/diagnosis/clinicRecord";
import {saveMasterAndDetail} from "@/api/patient/templateMaster.ts";
import {useDictStoreHook} from "@/store/modules/dict"
import {positiveNumber, posiNactiveNumber} from "@/utils/myRules"
import {useUserStoreHook} from "@/store/modules/user"
import diagnosisTable from "./diagnosisTable.vue"
import templateQuote from "./templateQuote.vue";
import History from "@/views/doctor/diagnosis/history.vue";
import {firstLetterResult} from "@/utils/pinyin";

const dictStore = useDictStoreHook()
let dictDataMap = ref(dictStore.isTypeGetData('sys_yes_no',
  'sys_user_sex', 'marriage_dict', 'nation_dict', 'nationality_dict', 'diagnosis_type', 'template_authority_type'))
const useUserStore = useUserStoreHook()
// 登录用户信息
const userInfo = <UserInfoBusi>useUserStore.user.userInfo
const {proxy} = getCurrentInstance() as any;
const clinicId = ref(proxy.$clinicId)
const patientId = ref(proxy.$patientId)
const clinicInfo = ref<any>(proxy.$clinicInfo)
// 历史、常用项目、模板弹出框 标题
const historyTitle = ref<string>("")
// 、模板弹出框 关闭打开状态
const historyOpen = ref<boolean>(false)
// 历史、常用项目、模板弹出框 内容状态 1：历史 2：常用项目 3：模板
const historyType = ref<number>(1)
const historyKey = ref<number>(0)
const formRef = ref();
// 生成模板弹出对话框
const formTemplateRef = ref();
const diagnosisTableRef = ref();
const templateQuoteRef = ref()
const historyQuoteRef = ref()
const open = ref(false);
const buttonLoading = ref(false);
const objectUrl = ref("")
const printPreviewRef = ref();
const templateParams = ref<any>({
  // 是否从门诊病历页面点击进入
  toClinic: true,
  pageNum: 1,
  pageSize: 10,
  type: "9",
  authorityType: userInfo.customerType != '3' ? '' : "0",
  title: "",
  titleInput: "",
  deptId: userInfo.loginDeptId,
  orgId: userInfo.orgId,
})
const templateForm = ref<any>({
  authorityType: "2",
  title: "",
  deptId: proxy.$currentSelectDept,
  orgId: userInfo.orgId,
  startFlag: "Y",
  type: "9",
})


const rulesTemplate = {
  authorityType: [
    {
      required: true,
      message: "权限不能为空",
      trigger: "change",
    },
  ],
  title: [
    {
      required: true,
      message: "模板主题名称不能为空",
      trigger: "blur",
    },
  ],
  startFlag: [
    {
      required: true,
      message: "状态不能为空",
      trigger: "blur",
    },
  ],
  deptId: [
    {
      required: true,
      message: "科室不能为空",
      trigger: "blur",
    },
  ],
};
const form = ref<any>({
  clinicId: "",
  patientId: "",
  fabingriqi: "",
  zhusu: "",
  liuxingbingshi: "",
  xianbingshi: "",
  jiwangshi: "",
  gerenshi: "",
  hunyushi: "",
  jiazushi: "",
  yuejingshi: "",
  allergyHistory: "",
  drugAllergyHistory: "",
  fabinghouqingkuang: "",
  tiwen: "",
  maibo: "",
  huxi: "",
  xueya: "",
  systolicPressure: "",
  diastolicPressure: "",
  bingshichenshuzhe: "",
  tigejiancha: "",
  fuzhujiancha: "",
  xiaojiefenxi: "",
  bingshicaijiriqi: "",
  dispose: "",
  suggestion: "",
  orgId: userInfo.orgId,
  remarks: "",
  symptomaticType: "",
  printDate: "",
  printUser: "",
  yiqing: "",
  fbg: "",
  healthPreach: "",
  mmmtbzmldm: "",
  mmmtbzmc: "",
  abzffbzdm: "",
  abzffbzmc: ""
})

const rules = ref<any>({
  zhusu: [
    {
      required: true, message: "主诉不能为空", trigger: "blur"
    }
  ],
  xianbingshi: [
    {
      required: true, message: "现病史不能为空", trigger: "blur"
    }
  ],
  tiwen: [
    {
      required: true, validator: posiNactiveNumber, trigger: "blur"
    }
  ],
  fbg: [
    {
      validator: posiNactiveNumber, trigger: "blur"
    }
  ],
  maibo: [
    {validator: positiveNumber, trigger: "blur"}
  ],
  huxi: [
    {validator: positiveNumber, trigger: "blur"}
  ]
})
listClinicRecordFun()

/** 获取病历信息 */
function listClinicRecordFun() {
  reset();
  const obj = {
    clinicId: proxy.$clinicId,
    patientId: proxy.$patientId
  }
  listClinicRecord(obj).then((response: any) => {
    if (response.data.length > 0) {
      form.value = response.data[0]
    } else {
      form.value.clinicId = clinicId.value
      form.value.patientId = patientId.value
      form.value.orgId = userInfo.orgId
    }
  })
}

/**
 * 病历打印
 */
function recordPrint() {
  let url = "/business/clinicRecord/recordPrint";
  const formData = new FormData()
  formData.append("id", form.value.id)
  formData.append("orgId", form.value.orgId)
  // pdf打印 、打印预览
  proxy.$printPdfPublic(url, formData).then(res => {
    if (res) {
      objectUrl.value = URL.createObjectURL(res)
      // nextTick(() => {
      // printPreviewRef.value.init(objectUrl.value)
      // })
    } else {
      console.error('打印失败')
    }
  })
}

// 表单重置
function reset() {
  form.value = {
    id: "",
    clinicId: "",
    patientId: "",
    fabingriqi: "",
    zhusu: "",
    liuxingbingshi: "",
    xianbingshi: "",
    jiwangshi: "",
    gerenshi: "",
    hunyushi: "",
    jiazushi: "",
    yuejingshi: "",
    allergyHistory: "",
    drugAllergyHistory: "",
    fabinghouqingkuang: "",
    tiwen: "",
    maibo: "",
    huxi: "",
    xueya: "",
    systolicPressure: "",
    diastolicPressure: "",
    bingshichenshuzhe: "",
    tigejiancha: "",
    fuzhujiancha: "",
    xiaojiefenxi: "",
    bingshicaijiriqi: "",
    dispose: "",
    suggestion: "",
    orgId: "",
    delFlag: "",
    createBy: "",
    createTime: "",
    updateBy: "",
    updateTime: "",
    remarks: "",
    symptomaticType: "",
    printDate: "",
    printUser: "",
    yiqing: "",
    fbg: "",
    healthPreach: "",
    mmmtbzmldm: "",
    mmmtbzmc: "",
    abzffbzdm: "",
    abzffbzmc: ""
  };
}

/**
 * 病历模板
 */
function medicalRecordTemplateClick() {
  // 强制刷新弹出框内容
  // historyKey.value = historyKey.value + 1
  historyType.value = 3
  historyOpen.value = true
}

/**
 * 历史模板
 */
function medicalRecordHistoryClick() {
  // 强制刷新弹出框内容
  // historyKey.value = historyKey.value + 1
  historyType.value = 4
  historyOpen.value = true
}

/**
 * 历史模板引用
 * @param form
 * @param type 1 追加 | 2覆盖
 */
function historyQuote(formChild: any, type: string) {
  if (type === '2') {
    form.value.zhusu = formChild.zhusu
    form.value.xianbingshi = formChild.xianbingshi
    form.value.liuxingbingshi = formChild.liuxingbingshi
    form.value.jiwangshi = formChild.jiwangshi
    form.value.gerenshi = formChild.gerenshi
    form.value.hunyushi = formChild.hunyushi
    form.value.jiazushi = formChild.jiazushi
    form.value.yuejingshi = formChild.yuejingshi
    form.value.fabinghouqingkuang = formChild.fabinghouqingkuang
    form.value.tigejiancha = formChild.tigejiancha
    form.value.allergyHistory = formChild.allergyHistory
    form.value.drugAllergyHistory = formChild.drugAllergyHistory
    form.value.fuzhujiancha = formChild.fuzhujiancha
    form.value.xiaojiefenxi = formChild.xiaojiefenxi
    form.value.dispose = formChild.dispose
    form.value.suggestion = formChild.suggestion
  } else {
    form.value.zhusu += formChild.zhusu
    form.value.xianbingshi += formChild.xianbingshi
    form.value.liuxingbingshi += formChild.liuxingbingshi
    form.value.jiwangshi += formChild.jiwangshi
    form.value.gerenshi += formChild.gerenshi
    form.value.hunyushi += formChild.hunyushi
    form.value.jiazushi += formChild.jiazushi
    form.value.yuejingshi += formChild.yuejingshi
    form.value.fabinghouqingkuang += formChild.fabinghouqingkuang
    form.value.tigejiancha += formChild.tigejiancha
    form.value.allergyHistory += formChild.allergyHistory
    form.value.drugAllergyHistory += formChild.drugAllergyHistory
    form.value.fuzhujiancha += formChild.fuzhujiancha
    form.value.xiaojiefenxi += formChild.xiaojiefenxi
    form.value.dispose += formChild.dispose
    form.value.suggestion += formChild.suggestion
  }
  form.value.tiwen = formChild.tiwen
  form.value.maibo = formChild.maibo
  form.value.huxi = formChild.huxi
  form.value.systolicPressure = formChild.systolicPressure
  form.value.diastolicPressure = formChild.diastolicPressure
  form.value.fbg = formChild.fbg
  historyCancel()
}

/**
 * 关闭历史、常用项目、模板弹出框
 */
function historyCancel() {
  // 清空模板明细信息
  if (historyType.value === 3) {
    nextTick(() => {
      templateQuoteRef.value.emptyItem
    })
  } else if (historyType.value === 4) {
    nextTick(() => {
      if (historyQuoteRef.value) {
        historyQuoteRef.value.emptyItem()
      }
    })
  }
  historyOpen.value = false
}


/** 提交按钮 */
function submitForm() {
  (formRef.value as any).validate(valid => {
    if (valid) {
      ElMessageBox.confirm('确定要保存门诊病历信息吗？',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }
      ).then(() => {
        submitOk(true)
      })
    }
  });
}

/**
 * 最终保存
 * @param isTips 是否弹出提示
 */
function submitOk(isTips: boolean) {
  buttonLoading.value = true;
  form.value.isUpdateDoctorId = "Y"
  if (form.value.id != '') {
    updateClinicRecord(form.value).then(() => {
      isTips ? ElMessage.success("门诊病历修改成功") : '';
      open.value = false;
      listClinicRecordFun()
    }).finally(() => {
      buttonLoading.value = false;
    });
  } else {
    addClinicRecord(form.value).then(() => {
      isTips ? ElMessage.success("门诊病历新增成功") : '';
      listClinicRecordFun()
    }).finally(() => {
      buttonLoading.value = false;
    });
  }
}

/**
 * 生成模板
 */
function generateTemplate() {
  (formRef.value as any).validate(valid => {
    if (valid) {
      resetTemplate()
      open.value = true
    }
  })
}

/**
 * 一键清空病历、诊断信息
 **/
function clearance() {
  ElMessageBox.confirm("是否确认删除治疗项目？", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
        clearanceMedicalRecord(clinicId.value).then(() => {
          ElMessage.success("清空成功")
          listClinicRecordFun()
          diagnosisTableRef.value.clearHisDiagnosisList()
        })
      }
    )
}

// 主题生成拼音码
function titleInput(value) {
  if (value) {
    templateForm.value.titleInput = firstLetterResult(value)
  } else {
    templateForm.value.titleInput = ""
  }
}


// 科室点击事件
function deptSelect(node) {
  templateForm.value.deptId = node.deptId
  templateForm.value.deptName = node.deptName
}

/**
 * 生成模板保存
 */
function submitFormTemplate() {
  (formTemplateRef.value as any).validate(valid => {
    if (valid) {
      let saveForm = form.value
      saveForm.title = templateForm.value.title
      saveForm.deptId = templateForm.value.deptId
      saveForm.authorityType = templateForm.value.authorityType
      saveForm.startFlag = templateForm.value.startFlag
      saveForm.type = "9"
      saveForm.orgId = userInfo.orgId
      saveMasterAndDetail(saveForm).then(() => {
        ElMessage.success("模板生成成功")
        cancelTemplate()
      })
    }
  })
}

function resetTemplate() {
  templateForm.value.title = ""
  templateForm.value.deptId = ""
  templateForm.value.authorityType = "2"
  templateForm.value.startFlag = "Y"
  templateForm.value.type = "9"
  templateForm.value.orgId = userInfo.orgId
}

function cancelTemplate() {
  open.value = false
  resetTemplate()
}


onBeforeUnmount(() => {
  if (form.value.zhusu) {
    submitOk(false)
  }
})


/***********************************  模板引用  **********************************/
function quoteOkIndex(obj: any) {
  debugger
  const id = form.value.id
  form.value = obj
  form.value.patientId = patientId.value
  form.value.clinicId = clinicId.value
  form.value.id = id
  historyCancel()
}
</script>

<style scoped>
.mt-2 {
  margin-top: -2px
}

.tigejiancha {
  margin-left: -14px;
}

:deep(.el-input-group__append) {
  width: 40px;
  padding: 0 5px;
}

:deep(.tigejiancha-input) {
  margin-left: -10px
}

:deep(.tigejiancha-input .el-input__wrapper .el-input__inner) {
  width: 45px
}

:deep(.el-form-item__error) {
  width: 140px;
}
</style>
